
// Copyright (C) Recursion Company. All rights reserved.

#include "stdafx.h"

CCurlWraper::CCurlWraper()
{
	m_pCurl = curl_easy_init();
	headers = NULL;
	proxyHeaders = NULL;
	connect_to = NULL;
	aliases = NULL;
	rcpts = NULL;
	ftpQuoteCmds = NULL;
	ftpPostQuoteCmds = NULL;
	ftpPreQuoteCmds = NULL;
}
	
void CCurlWraper::Cleanup()
{
	if (m_pCurl)
	{
		curl_easy_pause (m_pCurl, CURLPAUSE_ALL);
		curl_easy_cleanup (m_pCurl);
		m_pCurl = NULL;
	}

    ClearHeaderList();
	ClearProxyHeaderList();
	ClearConnectToList();
	ClearAliasesList();
	ClearRcptsList();
	ClearFtpQuoteCmdsList();
	ClearFtpPostQuoteCmdsList();
	ClearFtpPreQuoteCmdsList();
}
	
struct curl_slist* CCurlWraper::s_create_slist (const CMStringArray& sary)
{
	struct curl_slist* slist = NULL;

	const INT_P npCount = sary.GetCount ();
	for (INT_P npIndex = 0; npIndex < npCount; npIndex++)
	{
		struct curl_slist* temp = curl_slist_append (slist, GetMbsText (sary [npIndex], CVolMem (), NULL));
		if (temp == NULL)
		{
			s_safe_free_slist (slist);
			return NULL;
		}
		slist = temp;
	}

	return slist;
}
